package com.example.simple.work.controller;

import com.example.simple.work.service.ex.*;
import com.example.simple.work.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {
    /** 操作成功的状态码 */
    public static final int OK = 200;

    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable e){
        JsonResult<Void> result = new JsonResult<>(e);
        if(e instanceof EmployeeIdNotExistException){
            result.setState(4000);
            result.setMessage("员工信息工号不存在");
        }else if(e instanceof EmployeeIdDuplicatedException){
            result.setState(4001);
            result.setMessage("员工信息工号已存在");
        }else if(e instanceof InsertException){
            result.setState(4002);
            result.setMessage("员工信息输入时遇见未知错误");
        }else if(e instanceof EmployeeDeleteException){
            result.setState(4003);
            result.setMessage("员工信息删除时遇见未知错误");
        }else if(e instanceof EmployeeFindAllException){
            result.setState(4004);
            result.setMessage("员工信息查询所有时遇见未知错误");
        }else if(e instanceof EmployeeChangeException){
            result.setState(4005);
            result.setMessage("员工信息修改时遇见未知错误");
        }else if(e instanceof EmployeeIdNotNullException){
            result.setState(4005);
            result.setMessage("员工工号不能为空");
        }else if(e instanceof EmployeeInsertListException){
            result.setState(4006);
            result.setMessage("员工数据批量插入出现异常");
        }else if(e instanceof EmployeeInsertListIsNotExistException){
            result.setState(4007);
            result.setMessage("员工数据批量插入不能为空");
        }

        else if(e instanceof UserIdNotExistException){
            result.setState(4100);
            result.setMessage("管理员登录工号不存在");
        }else if(e instanceof UserPasswordErrorException){
            result.setState(4101);
            result.setMessage("管理员登录密码错误");
        }else if(e instanceof FacilityIdNotExistException){
            result.setState(4200);
            result.setMessage("设备信息id不存在");
        }else if(e instanceof FacilityException){
            result.setState(4201);
            result.setMessage("设备登记信息删除出现未知异常");
        }
        else if(e instanceof CheackingIdNotExistException){
            result.setState(4300);
            result.setMessage("考勤表id不存在");
        }else if(e instanceof CheackingDeleteException){
            result.setState(4301);
            result.setMessage("删除员工考勤信息时遇到了未知错误");
        }else if(e instanceof CheckingFindAllException){
            result.setState(4302);
            result.setMessage("查询所有员工考勤信息时遇到了未知错误");
        }else if(e instanceof CheckingUpdateException){
            result.setState(4303);
            result.setMessage("员工考勤修改过程中遇见了未知错误");
        }else if(e instanceof CheckingInsertListException){
            result.setState(4304);
            result.setMessage("员工考勤批量插入出现异常");
        }else if(e instanceof CheckingInsertListIsNotExistException){
            result.setState(4305);
            result.setMessage("员工考勤批量插入不能为空");
        }
        return result;
    }

}
